package com.liarjo.my_website_api.controller.messageBoard;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liarjo.my_website_api.controller.messageBoard.add.MessageBoardAddRequest;
import com.liarjo.my_website_api.controller.messageBoard.add.MessageBoardAddResult;
import com.liarjo.my_website_api.controller.messageBoard.page.MessageBoardPageRequest;
import com.liarjo.my_website_api.controller.messageBoard.page.MessageBoardPageResult;
import com.liarjo.my_website_api.pojo.MessageBoard;
import com.liarjo.my_website_api.pojo.MessageBoardBaseMapper;

@Service
public class MessageBoardService {
    @Autowired
    private MessageBoardBaseMapper messageBoardBaseMapper;
    @Autowired
    private MessageBoardMapper messageBoardMapper;

    public MessageBoardAddResult messageBoard(MessageBoardAddRequest messageBoardRequest) {
        MessageBoardAddResult messageBoardResult = new MessageBoardAddResult();
        return messageBoardResult;
    }

    public boolean add(MessageBoardAddRequest messageBoardRequest) {
        MessageBoard messageBoard = new MessageBoard();
        BeanUtils.copyProperties(messageBoardRequest, messageBoard);
        return messageBoardBaseMapper.insert(messageBoard) > 0;
    }

    public IPage<MessageBoardPageResult> page(MessageBoardPageRequest messageBoardPageRequest) {
        IPage<MessageBoardPageResult> page = new Page<>(messageBoardPageRequest.getCurrent(),messageBoardPageRequest.getSize());
        IPage<MessageBoardPageResult> pageResult = messageBoardMapper.page(page);

        return pageResult;
    }
}
